<template>

  <div class="work-info"
    v-if="state.workInfo">
    <van-sticky :offset-top="0">
      <van-config-provider :theme-vars="themeVars">

        <van-nav-bar title="职位详情"
          right-text="按钮"
          left-arrow
          @click-left="onClickLeft"
          @click-right="onClickRight">
          <template #right>
            <img class="collect"
              style="width:20px;height:20px"
              src="https://mina.52kfw.cn/uploads/attach/2022/06/20220617/645c9a245a7860781ffe48bebe940498.png"
              alt="">
          </template>
        </van-nav-bar>

      </van-config-provider>

    </van-sticky>
    <!-- 公司介绍卡片 -->
    <div class="card">

      <div class="header">
        <div class="title">{{state.workInfo.title}}</div>
        <div class="salary">{{state.workInfo.salary}}</div>
      </div>
      <div class="tag">{{state.workInfo.workRange}}|{{state.workInfo.workAddress}}|{{state.workInfo.education}}</div>
      <div class="welfare">
        <span v-for="(wel,index) in state.workInfo.welfare"
          :key="index">{{wel}}</span>

      </div>
      <div class="company-info">
        <div class="left">
          <div class="img"><img :src="state.workInfo.companyInfo[0].logoUrl"
              alt=""></div>
          <div class="info">
            <h2>{{state.workInfo.companyInfo[0].title}}{{state.workInfo.companyInfo[0].companyRange}}</h2>
            <p>
              <span>电子商务</span>
              <span>{{state.workInfo.companyInfo[0].companyType}}</span>
              <span>{{state.workInfo.companyInfo[0].companyNumber}}</span>
            </p>
          </div>

        </div>
      </div>

    </div>
    <div class="wrap">
      <div class="position-detail detail">
        <h3>职位详情</h3>
        <span>岗位职责:</span>
        <div class="list"
          v-for="(desc,index) in state.workInfo.description"
          :key="index">
          <p>{{desc.title}}</p>

        </div>
        <div class="look-more">
          ...
          <span>查看全部</span>

        </div>
      </div>
      <div class="job-requirements detail">
        <h3>任职资格</h3>
        <div class="list"
          v-for="(work,index) in state.workInfo.works"
          :key="index">
          <p>{{work.title}}</p>

        </div>
      </div>
    </div>
    <div class="diliver">
      <div class="btn"
        @click="goChat">立即沟通</div>
    </div>
    <ChatCom @update:closeChat="
        closeChat"
      v-if="showChat"
      :companyInfo="state.workInfo.companyInfo[0]">
    </ChatCom>
  </div>
</template>

<script lang="ts" setup>
  import ChatCom from '@/views/Message/Chat.vue'
  import { Toast } from 'vant'
  import { reactive, onMounted, ref } from 'vue'
  import { useRouter, useRoute } from 'vue-router'
  import { getWorkInfo, IWorkInfo } from '../../api/work'
  const router = useRouter()
  const route = useRoute()
  const emit = defineEmits(['backHnadler', 'onClickLeft'])
  const backHnadler = () => {
    emit('update:closeChat')
  }
  let showChat = ref(false)
  let closeChat = () => {
    showChat.value = false
  }
  const themeVars = {
    navBarBackgroundColor: 'linear-gradient( to right, #6db260, #3da632)',
    navBarTitleTextColor: '#fff',
    navBarIconColor: '#fff'
  }
  const props = defineProps({
    companyId: {
      type: String
    },
    workId: {
      type: String
    }
  })

  let state = reactive({
    workInfo: null
  })
  const onClickLeft = () => {
    emit('update:closeWork')
  }
  onMounted(() => {
    console.log(props.companyId, props.workId)
    getCompanyFunc()
  })
  const getCompanyFunc = async () => {
    try {
      let rs = await getWorkInfo(props.workId, props.companyId)
      // console.log(rs)
      state.workInfo = rs.data
    } catch (err) {}
  }
  const goChat = () => {
    console.log(111)

    const token = localStorage.getItem('token')
    if (!token) {
      // Toast({
      //   message: '请先登陆,跳转至登陆页面',
      //   onOpened:() => {
      //     router.push('/login')
      //   }
      // })
      Toast({
        message: '请先登陆',
        onClose() {
          router.push('/login')
        }
      })
      return
    }
    showChat.value = true
  }
</script>

<style lang="less" scoped>
@mainColor: #149639;
.work-info {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  background: #fff;
  width: 100vw;
  height: 100vh;
  padding-bottom: 20px;
  overflow: auto;
  .card {
    box-shadow: 0 0 10px -5px #149639;
    // padding: 20px 0 15px 0;
    width: 350px;
    margin: 13px auto 18px auto;
    border-radius: 10px;
    padding: 14px 13px 18px 13px;
    border-bottom: 1px solid #f4f4f4;
    .header {
      display: flex;
      justify-content: space-between;
      height: 20px;
      .title {
        font-size: 20px;
      }
      .salary {
        font-size: 15px;
        font-weight: 600;
        color: @mainColor;
      }
    }
    .tag {
      margin-top: 10px;
      font-size: 12px;
      color: #898989;
    }
    .welfare {
      margin-top: 10px;
      span {
        display: inline-block;
        background: #f4f4f4;
        color: #b7b7b7;
        // width: 35px;
        padding: 0 5px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        border-radius: 5px;
        margin-right: 5px;
      }
    }
    .company-info {
      margin-top: 10px;
      display: flex;
      justify-content: space-around;
      .left {
        display: flex;
        flex: 1;
        .img {
          width: 35px;
          height: 35px;
          border-radius: 50%;
          img {
            width: 35px;
            height: 35px;
          }
        }
        .info {
          margin-left: 10px;
          // display: flex;
          h2 {
            font-size: 13px;
          }
          p {
            margin-top: 5px;
            color: #b7b7b7;
            font-size: 12px;
            span {
              margin-right: 10px;
            }
          }
        }
      }
      .right {
        font-size: 12px;
        line-height: 25px;
        border: 1px solid @mainColor;
        text-align: center;
        height: 25px;
        width: 65px;
        color: @mainColor;
        border-radius: 20px;
        // margin: 10px auto;
      }
    }
  }
  .wrap {
    padding: 0 13px 0px 13px;
    .detail {
      margin-bottom: 10px;
      padding-bottom: 28px;
      border-bottom: 1px solid #f4f4f4;
      > h3 {
        font-weight: 600;
        font-size: 16px;
        color: #333333;
      }
      > span {
        display: inline-block;
        margin-top: 15px;
        color: #797979;
        font-size: 12px;
      }
      .list {
        margin-top: 10px;
        font-size: 12px;
        color: #797979;
        line-height: 20px;
      }
      .look-more {
        margin-top: 15px;
        span {
          color: @mainColor;
        }
      }
    }
  }

  .diliver {
    position: fixed;
    bottom: 0;
    left: 0;
    border-top: 1px solid #f4f4f4;
    padding: 10px 13px;
    .btn {
      margin: 0 auto;
      color: #fff;
      width: 350px;
      height: 35px;
      line-height: 35px;
      text-align: center;
      background-color: @mainColor;
      border-radius: 15px;
      font-size: 15px;
    }
  }
}
</style>
